#define  _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
const int cycles[10][5] = {
	{0},
	{1},
	{2,4,8,6},
	{3,9,7,1},
	{4,6},
	{5},
	{6},
	{7,9,3,1},
	{8,4,2,6},
	{9,1}
};

int main() {
	int n;
	scanf("%d", &n);
	int h = n % 10;
	int cyclesnum = sizeof(cycles[h]) / sizeof(cycles[h][0]);
	int zui = (n - 1) % cyclesnum;
	printf("%d\n", cycles[h][zui]);

	return 0;
}